home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / jaz_clib.arc / JZWLDCRD.C < prev    next >
Text File  |  1989-04-09  |  1KB  |  53 lines

  1.  
  2. /*
  3. ┌────────────────────────────────────────────────────────────────────────────┐
  4. │jzwldcrd                                     │
  5. │Implement a dumb wildcard search for files                     │
  6. │Synopsis:                                     │
  7. │   match = jzwldcrd("TEST.FIL","??ST.*");                                   │
  8. │                                         │
  9. └────────────────────────────────────────────────────────────────────────────┘
  10. */
  11. #include <ctype.h>
  12. jzwldcrd(fstr,fcard)
  13. char *fstr;            /* string to search on */
  14. char *fcard;            /* wild cards           */
  15. {
  16.   int wmatch;
  17.   int w,wlen,x;
  18.   int wch1,wch2;
  19.  
  20.   wmatch = 1;
  21.   wlen = strlen(fcard);
  22.  
  23.   w = 0;
  24.   while (wmatch && (w < wlen) && *fstr)
  25.     switch(fcard[w]) {
  26.       case '?' :                        /* character substitution */
  27.          w ++;
  28.          fstr++;        /* look at next character */
  29.          break;
  30.       case '*' :
  31.          x = index(fstr,'.');   /* look for dot */
  32.          if (x > 0) {
  33.            fstr += (int) x ;    /* get past period */
  34.            w ++;
  35.          }
  36.          else {
  37.            w = wlen;        /* exit loop */
  38.            wmatch = (fcard[wlen-1] == '*');
  39.          }
  40.          break;
  41.       default  :
  42.          wch1 = *fstr++;
  43.          wch2 = fcard[w++];
  44.          wmatch = (toupper(wch1) == toupper(wch2));
  45.          break;
  46.     }
  47.  
  48.   if (fcard[w] && (fcard[w] != '*'))
  49.     return(0);
  50.   else
  51.     return(wmatch);
  52. }
  53.